﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SoccerEvaluator.Common;
using System.Xml;

namespace SoccerEvaluator.Business
{
    /// <summary>
    /// Fabrica de objetos
    /// </summary>
    internal class Factory
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        internal static TemplateInfo CreateResultInfo(XmlAttributeCollection attributes)
        {
            TemplateInfo item = new TemplateInfo();

            #region PointCatchScores
            try
            {
                item.CatchScore = int.Parse(attributes["PointCatchScores"].Value);
            }
            catch (Exception ex)
            {

                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region ExactScore
            try
            {
                item.ExactScore = int.Parse(attributes["ExactScore"].Value);
            }
            catch (Exception ex)
            {

                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region UserName
            try
            {
                item.User = attributes["UserName"].Value;
            }
            catch (Exception ex)
            {

                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region ProjectMode
            try
            {
                item.ProjectMode = int.Parse(attributes["ProjectMode"].Value);
            }
            catch (Exception ex)
            {

                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region UrlScores
            try
            {
                item.UrlScores = attributes["UrlScores"].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region TableResults
            try
            {
                item.TableResults = attributes["TableResults"].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region Logo
            if (attributes["Logo"] != null)
            {
                item.Logo = attributes["Logo"].Value;
            }
            #endregion

            #region EnableUpdates
            try
            {
                item.EnableUpdates = bool.Parse(attributes["EnableUpdates"].Value);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region StartDate
            try
            {
                item.StartDate = DateTime.Parse(attributes["StartDate"].Value);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region EndDate
            try
            {
                item.EndDate = DateTime.Parse(attributes["EndDate"].Value);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            
            

            return item;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlAttributeCollection"></param>
        /// <returns></returns>
        internal static TemplateScoreInfo CreateScoreInfo(XmlAttributeCollection attributes)
        {
            TemplateScoreInfo item = new TemplateScoreInfo();

            item.Date = DateTime.Parse(attributes["Date"].Value);

            item.Location = attributes["Location"].Value;

            item.Index = int.Parse(attributes["Index"].Value);
            item.Local = attributes["Local"].Value;
            item.LocalGoals = int.Parse(attributes["LocalGoals"].Value);
            item.Visitor = attributes["Visitor"].Value;
            item.VisitorGoals = int.Parse(attributes["VisitorGoals"].Value);

            return item;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        internal static ProviderInfo CreateProviderInfo(XmlAttributeCollection attributes)        
        {
            ProviderInfo item = new ProviderInfo();

            #region UrlScores
            try
            {
                item.UrlScores = attributes["UrlScores"].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            #region TableResults
            try
            {
                item.TableResults = attributes["TableResults"].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            #endregion

            return item;
        }
    }
}
